package cate.common.table.item.rune.sheet;

import cate.common.table.ESheet;
import cate.common.table.item.rune.row.RuneRecastSkillTypeRow;
import com.fasterxml.jackson.annotation.JsonIgnore;
import easy.java.dev.note.NoteClass;

import java.util.Comparator;
import java.util.List;

@NoteClass(value = "徽章技能特殊洗练")
public class RuneRecastSkillTypeSheet extends ESheet<RuneRecastSkillTypeRow> {

    @Override
    public String getSheetName() {
        return "徽章技能特殊洗练";
    }

    @Override
    protected RuneRecastSkillTypeRow buildRow() {
        return new RuneRecastSkillTypeRow();
    }

    @JsonIgnore
    public RuneRecastSkillTypeRow find(List<Integer> levels) {
        for (RuneRecastSkillTypeRow row : this.getList()) {
            if (match(row.levelCombo, levels)) {
                return row;
            }
        }
        return null;
    }

    private boolean match(List<Integer> l1, List<Integer> l2) {
        if (l1 == null || l2 == null) {
            return false;
        }
        if (l1.size() != l2.size()) {
            return false;
        }
        int size = l1.size();
        if (size == 0) {
            return false;
        }
        l1.sort(Comparator.comparing(e -> e));
        l2.sort(Comparator.comparing(e -> e));
        for (int i = 0; i < size; i++) {
            Integer a = l1.get(i);
            Integer b = l2.get(i);
            if (a == null || b == null) {
                return false;
            }
            if (!a.equals(b)) {
                return false;
            }
        }
        return true;
    }
}
